#include "thread_utils.hpp"

auto dummyFunction(int a, int b, bool sleep) {
  std::cout << "dummyFunction(" << a << "," << b << ")" << std::endl;
  std::cout << "dummyFunction output=" << a + b << std::endl;

  if(sleep) {
    std::cout << "dummyFunction sleeping..." << std::endl;

    using namespace std::literals::chrono_literals;
    std::this_thread::sleep_for(5s);
  }

  std::cout << "dummyFunction done." << std::endl;
}


int main(int, char **) {
  using namespace Common;

  auto t1 = createAndStartThread(-1, "dummyFunction1", dummyFunction, 12, 21, false);
  auto t2 = createAndStartThread(1, "dummyFunction2", dummyFunction, 15, 51, true);
  auto t3 = createAndStartThread(5, "dummyFunction3", dummyFunction, 1, 2, true);
  auto t4 = createAndStartThread(8, "dummyFunction4", dummyFunction, 3, 4, true);
  auto t5 = createAndStartThread(15, "dummyFunction5", dummyFunction, 5, 6, true);
  auto t6 = createAndStartThread(0, "dummyFunction6", dummyFunction, 7, 8, true);

  std::cout << "main waiting for threads to be done." << std::endl;
  t1->join();
  t2->join();
  t3->join();
  t4->join();
  t5->join();
  t6->join();
  std::cout << "main exiting." << std::endl;

  delete t1;
  delete t2;
  delete t3;
  delete t4;
  delete t5;
  delete t6;

  return 0;
}